IF EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'SubjectInDegreeCourse' AND xtype = 'U')
BEGIN
	DROP TABLE SubjectInDegreeCourse
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'SubjectInDegreeCourse' AND xtype = 'U')
BEGIN
	CREATE TABLE SubjectInDegreeCourse
	(
		SubjectInDegreeCourseId				int not null IDENTITY(1,1),
		ProfessorId							int not null,
		SubjectId								int not null,
		DegreeCourseId							int not null,
	)
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'pk_SubjectInDegreeCourseId' AND xtype = 'PK')
BEGIN
	ALTER TABLE SubjectInDegreeCourse
	ADD CONSTRAINT pk_SubjectInDegreeCourseId PRIMARY KEY ([SubjectInDegreeCourseId])
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'fk_cd_Professor' AND xtype = 'F')
BEGIN
	ALTER TABLE SubjectInDegreeCourse
	ADD CONSTRAINT	fk_cd_Professor FOREIGN KEY ([ProfessorId])
	REFERENCES Professors
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'fk_cd_Subject' AND xtype = 'F')
BEGIN
	ALTER TABLE SubjectInDegreeCourse
	ADD CONSTRAINT	fk_cd_Subject FOREIGN KEY ([SubjectId])
	REFERENCES Subjects
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'fk_cd_DegreeCourse' AND xtype = 'F')
BEGIN
	ALTER TABLE SubjectInDegreeCourse
	ADD CONSTRAINT	fk_cd_DegreeCourse FOREIGN KEY ([DegreeCourseId])
	REFERENCES DegreeCourses
END
GO

